import Vue from 'vue';
import VueRouter from 'vue-router';
import Store from '@/store';
import { getToken } from '@/utils/auth';
// import axios from 'axios';
// 登录页面
import Login from '@/views/Login.vue';
// 主页
import Family from '@/views/Family.vue';
// 监控中心
import WorkChart from '@/views/Workshop/Chart';
import WorkData from '@/views/Workshop/Data';
import WorkActual from '@/views/Workshop/Actual';
import WorkProduct from '@/views/Workshop/Product';
// 生产统计
import ProductionWorker from '@/views/Production/ProductionWorker.vue';
import ProductionParams from '@/views/Production/ProductionParams.vue';
import ProductionTrack from '@/views/Production/ProductionTrack.vue';
import ProductionData from '@/views/Production/ProductionData.vue';
// 环境管理
import HistoryEnvironment from '@/views/Environment/HistoryEnvironment.vue';
import Environment from '@/views/Environment/Environment.vue';
//  能源管理
import Energy from '@/views/Energy/History.vue';
import EnergyActual from '@/views/Energy/Actual.vue';
import EnergyLine from '@/views/Energy/Line.vue';
import EnergyPz from '@/views/Energy/Pz.vue';
import EnergyGx from '@/views/Energy/Gongxu.vue';
import EnergyDetail from '@/views/Energy/Detail.vue';
// 生产调度管理
import DispatchPersonel from '@/views/ProductionDispatch/Personnel.vue';
import DispatchPersonelDetail from '@/views/ProductionDispatch/modules/PersonalDetail.vue';
import DispatchScheduling from '@/views/ProductionDispatch/Scheduling.vue';
import DispatchShifts from '@/views/ProductionDispatch/Shifts.vue';
import Socialsignin from '../components/Socialsignin';
import Authredirect from '../components/Authredirect';
import Payment from '../components/Payment.vue';
import Loans from '../components/Loans.vue';
import Purorder from '../components/Purorder.vue';
import shopAdd from '../components/shopAdd.vue';
import Purware from '../components/Purware.vue';
import Purchase from '../components/Purchase.vue';
import Commodhao from '../components/Commodhao.vue';
import Salesreturn from '../components/Salesreturn.vue';
import Basicment from '../components/Basicment.vue';
import Basicperson from '../components/Basicperson.vue';
import Systemrole from '../components/Systemrole.vue';
import Systemtion from '../components/Systemtion.vue';
import SystemtionAdd from '../components/SystemtionAdd.vue';
import TableMan from '../components/TableMan.vue';
import Commodinfor from '@/views/Commodinfor';
import CommodinforAdd from '@/views/Commodinfor/add.vue';
import CommodinforDetail from '@/views/Commodinfor/detail.vue';
import Commodtem from '@/views/Commodtem';
import CommodtemAdd from '@/views/Commodtem/add.vue';
import CommodtemDetail from '@/views/Commodtem/detail.vue';
import Quota from '@/views/Quota/index.vue';

//薪资报表
import SalaryReportXiSha from '@/views/SalaryReport/XiSha/index.vue';
import SalaryReportQianFang from '@/views/SalaryReport/QianFang/index.vue';
import SalaryReportLuoTong from '@/views/SalaryReport/LuoTong/index.vue';

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

Vue.use(VueRouter);

const routes = [
  // 项目启动后默认显示登录界面
  {
    path: '/',
    redirect: '/Login'
  },
  {
    path: '/Login',
    name: 'Login',
    component: Login
  },
  {
    // 登录成功后进入管理页面的首页
    path: '/Family',
    name: 'Family',
    component: Family,

    children: [
      // 登录
      {
        path: '/Login',
        component: Login
      },
      // 车间总览
      {
        path: '/WorkChart',
        component: WorkChart
      },
      // 车台数据
      {
        path: '/WorkData',
        component: WorkData
      },
      // 实时开台
      {
        path: '/WorkActual',
        component: WorkActual
      },
      // 生产看板
      {
        path: '/WorkProduct',
        component: WorkProduct
      },
      // 历史数据查询
      {
        path: '/ProductionData',
        component: ProductionData
      },
      // 历史轨迹曲线
      {
        path: '/ProductionTrack',
        component: ProductionTrack
      },
      // 参数修改记录
      {
        path: '/ProductionParams',
        component: ProductionParams
      },
      // 用工历史记录
      {
        path: '/ProductionWorker',
        component: ProductionWorker
      },
      // 告警设置
      {
        path: '/Systemtion',
        component: Systemtion
      },
      // 添加告警设置
      {
        path: '/SystemtionAdd',
        component: SystemtionAdd
      },
      // 告警明细
      {
        path: '/Systemrole',
        component: Systemrole
      },
      // 告警监控
      {
        path: '/Basicperson',
        component: Basicperson
      },
      // 告警统计
      {
        path: '/Basicment',
        component: Basicment
      },
      // 实时查询
      {
        path: '/EnergyActual',
        component: EnergyActual
      },
      // 历史数据
      {
        path: '/EnergyHistory',
        component: Energy
      },
      // 电流折线图
      {
        path: '/EnergyLine',
        component: EnergyLine
      },
      // 品种电耗
      {
        path: '/EnergyPz',
        component: EnergyPz
      },
      // 工序电耗
      {
        path: '/EnergyGx',
        component: EnergyGx
      },
      // 电耗明细
      {
        path: '/EnergyDetail',
        component: EnergyDetail
      },
      // 环境实时查询
      {
        path: '/Environment',
        component: Environment
      },
      // 环境历史数据
      {
        path: '/HistoryEnvironment',
        component: HistoryEnvironment
      },
      // 订单管理
      {
        path: '/Basiclier',
        component: () => import('@/views/Basiclier')
      },
      // 订单新增
      {
        path: '/Basiclier/new',
        component: () => import('@/views/basiclier/new')
      },
      // 订单详情
      {
        path: '/Basiclier/detail',
        component: () => import('@/views/basiclier/detail')
      },
      // 二级订单详情
      {
        path: '/Basiclier/detailSec',
        component: () => import('@/views/basiclier/detailSec')
      },
      // 订单详情-不可编辑
      {
        path: '/Basiclier/completed',
        component: () => import('@/views/basiclier/completed')
      },
      // 订单跟踪
      {
        path: '/Salesreturn',
        component: Salesreturn
      },
      // 定额表管理
      {
        path: '/Commodhao',
        component: Commodhao
      },
      /*** 生产计划管理 ***/
      // 预排计划管理
      {
        path: '/PrePlan',
        component: () => import('@/views/ProductionPlan/PrePlan/index.vue')
      },
      // 日计划管理
      {
        path: '/DailyPlan',
        component: () => import('@/views/ProductionPlan/DailyPlan/index.vue')
      },
      // 工艺单管理
      {
        path: '/ProcessPlan',
        component: () => import('@/views/ProductionPlan/Process.vue')
      },
      // 工艺单变更管理
      {
        path: '/ChangePlan',
        component: () => import('@/views/ProductionPlan/Change.vue')
      },
      // 工艺单变更管理
      {
        path: '/Commodinfor',
        component: Commodinfor
      },
      {
        path: '/Commodinfor/Add',
        component: CommodinforAdd
      },
      {
        path: '/Commodinfor/Detail',
        component: CommodinforDetail
      },
      // 工艺模版管理
      {
        path: '/Commodtem',
        component: Commodtem
      },
      {
        path: '/Commodtem/Add',
        component: CommodtemAdd
      },
      {
        path: '/Commodtem/Detail',
        component: CommodtemDetail
      },
      // 排班管理
      {
        path: '/DispatchScheduling',
        component: DispatchScheduling
      },
      // 人员管理
      {
        path: '/DispatchPersonnel',
        component: DispatchPersonel
      },
      {
        path: '/DispatchPersonnel/Detail',
        component: DispatchPersonelDetail
      },
      // 轮班管理
      {
        path: '/DispatchShifts',
        component: DispatchShifts
      },
      // 工单执行反馈
      {
        path: '/Socialsignin',
        component: Socialsignin
      },
      // 报表管理
      {
        path: '/TableMan',
        component: TableMan
      },
      // 品种单价设定
      {
        path: '/Purchase',
        component: Purchase
      },
      // 品种单价设定添加
      {
        path: '/Purware',
        component: Purware
      },
      // 计件工资算法管理
      {
        path: '/Purorder',
        component: Purorder
      },
      // 计件工资算法添加前纺清联
      {
        path: '/shopAdd',
        component: shopAdd
      },
      // 计件工资日度核算管理
      {
        path: '/Loans',
        component: Loans
      },
      // 计件工资月度核算管理
      {
        path: '/Payment',
        component: Payment
      },
      // 计件工资数据修正
      {
        path: '/Authredirect',
        component: Authredirect
      },
      // 系统管理
      {
        path: '/Dict',
        component: () => import('@/views/dict')
      },
      {
        path: '/Quota',
        component: Quota
      },
      {
        path: '/SalaryReportXiSha',
        component: SalaryReportXiSha
      },
      {
        path: '/SalaryReportQianFang',
        component: SalaryReportQianFang
      },
      {
        path: '/SalaryReportLuoTong',
        component: SalaryReportLuoTong
      }
    ],
    beforeEnter: (to, from, next) => {
      const token = getToken();

      if (!token && to.path !== '/Login') {
        next({ path: '/Login', replace: true });
      } else if (token) {
        Store.dispatch('common/getDict', { dict: 'organization', name: 'org' }); // 查询组织
        Store.dispatch('common/getDict', { dict: 'workshop', name: 'cj' }); // 查询车间
        Store.dispatch('common/getDict', {
          dict: 'working_procedure',
          name: 'gx'
        }); //
        Store.dispatch('common/getDict', { dict: 'varieties', name: 'pz' });
        Store.dispatch('common/getDict', { dict: 'branch', name: 'branch' });
        Store.dispatch('common/getDict', {
          dict: 'bc',
          name: 'bc'
        });
        Store.dispatch('common/getDict', {
          dict: 'workType',
          name: 'wt'
        });
        Store.dispatch('common/getDict', {
          dict: 'group',
          name: 'group'
        });
        Store.dispatch('common/getDict', {
          dict: 'attendanceStatus',
          name: 'kq'
        });

        //Store.dispatch('common/getPzOption');
        //Store.dispatch('common/getCjOption');
        //Store.dispatch('common/getGxOption');
        next();
      } else {
        next();
      }
    }
  }
];

const router = new VueRouter({
  mode: 'hash',
  // mode: 'history',
  base: process.env.BASE_URL,
  routes
});

export default router;
